package com.gitee.cashzhang27.test.boot.activiti.config;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

/**
 * @author Cash Zhang
 * @version v1.0
 * @since 2019/04/12 11:34
 */
public class GenericResponseWrapper extends HttpServletResponseWrapper { 
  private ByteArrayOutputStream output;
  private int contentLength;
  private String contentType;

  public GenericResponseWrapper(HttpServletResponse response) { 
    super(response);
    output=new ByteArrayOutputStream();
  } 

  public byte[] getData() { 
    return output.toByteArray(); 
  }

  @Override
  public ServletOutputStream getOutputStream() { 
    return new FilterServletOutputStream(output); 
  }

  @Override
  public PrintWriter getWriter() { 
    return new PrintWriter(getOutputStream(),true); 
  }

  @Override
  public void setContentLength(int length) { 
    this.contentLength = length;
    super.setContentLength(length); 
  } 

  public int getContentLength() { 
    return contentLength; 
  } 

  @Override
  public void setContentType(String type) { 
    this.contentType = type;
    super.setContentType(type); 
  }

  @Override
  public String getContentType() { 
    return contentType; 
  } 
} 
